| Conditions | 4 |
| Paths | 4 |
| Total Lines | 18 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | 'use strict'; |
||
| 12 | function distanceLink(p, a, b) { |
||
| 13 | /* http://stackoverflow.com/questions/849211 */ |
||
| 14 | var l2 = distance(a, b); |
||
| 15 | if (l2 === 0) { |
||
| 16 | return distance(p, a); |
||
| 17 | } |
||
| 18 | var t = ((p.x - a.x) * (b.x - a.x) + (p.y - a.y) * (b.y - a.y)) / l2; |
||
| 19 | if (t < 0) { |
||
| 20 | return distance(p, a); |
||
| 21 | } |
||
| 22 | if (t > 1) { |
||
| 23 | return distance(p, b); |
||
| 24 | } |
||
| 25 | return distancePoint(p, { |
||
| 26 | x: a.x + t * (b.x - a.x), |
||
| 27 | y: a.y + t * (b.y - a.y) |
||
| 28 | }); |
||
| 29 | } |
||
| 30 | |||
| 37 |